package com.doit.day01;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;

import java.io.IOException;

public class CreateIndex {
    public static void main(String[] args) throws IOException {
        //获取RestHighLevelClient的客户端
        //httphost需要传三个参数
        //第一个参数：主机名
        //第二个参数：端口号
        //第三个参数：协议名
        RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", 9200, "http")));

        //创建一个创建索引的请求
        CreateIndexRequest request = new CreateIndexRequest("java");

        //创建索引
        CreateIndexResponse response = client.indices().create(request, RequestOptions.DEFAULT);

        //查看响应结果
        boolean acknowledged = response.isAcknowledged();

        System.out.println("返回的结果是："+acknowledged);

        //关闭客户端
        client.close();

    }
}
